/*
 * @Description: 
 * @Author: yyh
 * @Date: 2022-03-03 00:13:56
 * @LastEditors: yyh
 * @LastEditTime: 2022-04-23 01:07:22
 */
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import './styles/element-variables.scss'
import * as echarts from 'echarts'

Vue.config.productionTip = false
Vue.prototype.$echarts = echarts

import http from './http'
Vue.prototype.$http = http

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')

// 路由拦截器
router.beforeEach((to, from, next) => {
    // 判断该路由是否需要登录权限
    if (to.meta.requireAuth) {
        // 通过sessionStorage获取当前的用户id是否存在
        if (window.sessionStorage.getItem('id')) {
            next();
        }
        else {
            next({
                path: '/'
            })
        }
        if (to.meta.permission) {
            if (!to.meta.permission.includes(sessionStorage.getItem("role"))) {
                next({
                    path: '*'
                })
            }
        }
    }
    next();
})
